# -*- coding: utf-8 -*-
# @time: 2024/6/6 16:31
# @file: covskew
# @author: tyshixi08

from get_data.covprice_mid import *

# 获取转债价格的价格偏度
def covskew(code=code_ls(), start_date = month_ls()[0].replace('-','') + '01', end_date = month_ls()[-1].replace('-','') + '01'):
    df = get_bond_price(code, start_date, end_date)
    df_covskew = df.groupby('date')['close'].skew().reset_index().rename(columns={'close':'covskew'})
    return df_covskew

# 数据存档
def covskew_save():
    excel_file_path = 'covskew.csv'
    #if os.path.exists('原始数据/' + excel_file_path):
    #    df = pd.read_csv('原始数据/' + excel_file_path)
    #    return df
    #else:
    save_CSV(covskew(), 'get_data/原始数据/' + excel_file_path.split('.')[0])
    df = pd.read_csv('get_data/原始数据/' + excel_file_path)
    return df
